package com.frcdi.qms.web.controller.flowable;


import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.domain.ProcessConfig;
import com.frcdi.qms.service.ProcessConfigService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 功能描述
 *
 * @author: author
 * @date: 2024年04月02日 16:45
 */
@RestController
@RequestMapping("processConfig")
public class ProcessConfigController extends BaseController {
    @Autowired
    private ProcessConfigService configService;

    @ApiOperation("查询列表")
    //@PreAuthorize("@ss.hasPermi('masterData:change:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessConfig processConfig)
    {
        startPage();
        List<ProcessConfig> list = configService.list(processConfig);
        return getDataTable(list);
    }

    /**
     * 获取详细信息
     */
    @ApiOperation("获取详细信息")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId)
    {
        ProcessConfig config = configService.getById(configId);
        return success(config);
    }

    @Transactional
    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@RequestBody ProcessConfig processConfig)
    {
        processConfig.setCreateBy(getUsername());
        processConfig.setCreateTime(new Date());
        return toAjax(configService.insert(processConfig));
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessConfig processConfig)
    {
        processConfig.setUpdateBy(getUsername());
        processConfig.setUpdateTime(new Date());
        return toAjax(configService.updateById(processConfig));
    }
}
